import torch


def metric_mPA(pred, target):
    return (
        1
        / 3
        * (pred.argmax(dim=1) == target[:, 0]).float().sum()
        / (pred.argmax(dim=1) == 0).float().sum()
        + 1
        / 3
        * (pred.argmax(dim=1) == target[:, 0]).float().sum()
        / (pred.argmax(dim=1) == 1).float().sum()
    )


def metric_mIOU(pred, target):
    return (
        1
        / 3
        * (
            (pred.argmax(dim=1) == target[:, 0]).float().sum()
            / (torch.ones_like(pred[0]).sum() - pred.argmax(dim=1) == 0).float().sum()
            + (pred.argmax(dim=1) == target[:, 1]).float().sum()
            / (torch.ones_like(pred[0]).sum() - pred.argmax(dim=1) == 0).float().sum()
        )
    )
